﻿/*
____
 L|ypps Web controls for ASP.NET

Copyright (c) 2009 Alessandro Zifiglio, http://www.Typps.com
EMail: alessandro@Typps.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
namespace Typps
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.IO;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.Design;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    /// <summary>
    /// Provides a type converter that retrieves a list of 
    /// <see cref="T:System.Web.UI.WebControls.HyperLink"></see>
    /// or
    /// <see cref="T:System.Web.UI.HtmlControls.HtmlAnchor"></see>
    /// controls in the current container.
    /// </summary>
    class SkinConverter : StringConverter
    {
        #region Constructors

        public SkinConverter()
        {
            // constructor
        }

        #endregion Constructors

        #region Methods

        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (context == null)
            {
                return null;
            }
            IDesignerHost service = (IDesignerHost)context.GetService(typeof(IDesignerHost));
            if (service == null)return null;

            IComponent component = context.Instance as IComponent;
            if (component == null) return null;

            string skinFolder = ((ITheming)component).CustomSkinFolder;
            List<string> skinsList = new List<string>(new string[] { "None" });
            if (!string.IsNullOrEmpty(skinFolder))
            {
                DirectoryInfo di1 = new DirectoryInfo(Helper.MapPath(service, skinFolder, PathType.Physical));
                if (di1.Exists)
                {
                    DirectoryInfo[] diList = di1.GetDirectories();
                    foreach (DirectoryInfo di2 in diList)
                        skinsList.Add(di2.Name);
                }
            }
            return new TypeConverter.StandardValuesCollection(skinsList.ToArray());
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return (context != null);
        }

        #endregion Methods
    }
}